from contextlib import contextmanager


class Resource:
    def query(self):
        print('querying...')


@contextmanager
def resouce():
    print('resource connected')
    yield Resource()
    print('connection closed')


with resouce() as r:
    r.query()
